#!/usr/bin/env python

# Author: Blaise Gassend

import rospy, os, sys
from sound_play.msg import SoundRequest
from find_object_2d.msg import ObjectsStamped
from sound_play.libsoundplay import SoundClient
a = 0

def sleep(t):
    try:
        rospy.sleep(t)
    except:
        pass


def callback(data):
    # rospy.loginfo(rospy.get_caller_id()+" I heard %s",data.objects)
    # 判读话题中物体编号是否与待识别的药品一致
    if data.objects.data.ObjectId1 == "14.0":
    # if data.objects.objects[0]=="14.0":
    # if "12.0" in data.objects.data[0]:
    # if data.objects.data[0] == "12.0":
        a = 1
        print('hahahahahahaha')
        rospy.Subscriber("objectsStamped", ObjectsStamped, callback, queue_size=1)

        
if __name__ == '__main__':
    rospy.init_node('soundplay_test', anonymous = True)
    soundhandle = SoundClient()

    rospy.sleep(1)
    # 订阅物体识别结果话题
    rospy.Subscriber("objectsStamped", ObjectsStamped, callback)
    soundhandle.stopAll()


    #print
    #print 'Try to play wave files that do not exist.'
    #soundhandle.playWave('17')
    #soundhandle.playWave('dummy')

    if a == 1:
        # 播报识别结果
        print ('identify success')
        soundhandle.say('I have successfully identified the medicine!')
        sleep(3)
    rospy.spin()
    

   